require(["../../conf/config.js"],function(){
	//头部导航
	require(["loginTop"],function(loginTop){
		loginTop();
	})
	
	//注册
	require(["jquery","getCookie","setCookie"],function($,getCookie,setCookie){
		//let person = document.getElementById("person-add");
		let add_right = document.getElementById("add-right-now");
		let callnum = document.getElementsByClassName("callnum")[0];
		let msgnum = document.getElementsByClassName("msgnum")[0];
		let pwd = document.getElementsByClassName("pwd")[0];
		let again_pwd = document.getElementsByClassName("again-pwd")[0];
		
		let isTrue = [];
		
		//手机号
		callnum.addEventListener("blur",function(){
			//console.log(this)
			if(/^1\d{10}/.test(this.value)){
				isTrue[0] = true;
				this.style.borderColor = "green";
			}else{
				isTrue[0] = false;
				this.style.borderColor = "red";
			}
		})
		
		//短信验证码
		msgnum.addEventListener("blur",function(){
			isTrue[1] = true;
			this.style.borderColor = "green";
		})
		
		//密码
		pwd.addEventListener("blur",function(){
			//console.log(this)
			if(this.value == ""){
				isTrue[2] = false;
				this.style.borderColor = "red";
			}
		})
		pwd.addEventListener("input",function(){
			//密码不能少于8位
					
			if(this.value.length >= 8) {
				isTrue[2] = true;
				this.style.borderColor = "green";
			}else{
				isTrue[2] = false;
				this.style.borderColor = "red";
			}
		})
		again_pwd.addEventListener("blur",function(){
			//密码不能少于8位
					
			if((this.value == pwd.value )&& (this.value!="")) {
				isTrue[3] = true;
				this.style.borderColor = "green";
			}else{
				isTrue[3] = false;
				this.style.borderColor = "red";
			}
		})
		
		
		//判断信息是否可以提交
		add_right.addEventListener("click",function(){
			
			let result = isTrue.every(function(item){ //every有一个不满足的就返回false
				return item;
			})
			
			//判断信息是否都为空，直接点击
			if(callnum.value==""||pwd.value==""||again_pwd.value==""){
				result = false;
			}
			
			//判断填写的信息是否有不合法的
			if(result){
				alert("成功！");
//				let days = new Date();
//				days.setDate(days.getDate() + 5); //创建存在时间
				
				//判断是否已经存在了存储用户的cookie,为空就创建
				if(document.cookie == ""){
//					document.cookie = "userId="+ callnum.value+";expires="+days+";";
//					document.cookie = "userPwd="+pwd.value+";expires="+days+";";
					setCookie("userId",callnum.value,10);
					setCookie("userPwd",pwd.value,10);
				}else{
					//console.log(document.cookie);
					//console.log(getCookie("userId"));
					//将id和pwd的cookie分别取出来，然后再将新的id和pwd追加进去
					let u_id = getCookie("userId");
					let u_pwd = getCookie("userPwd");
					
					u_id[1] += "%"+callnum.value;
					u_pwd[1] += ","+pwd.value;
					
//					document.cookie = "userId="+ u_id[1]+";expires="+days+";";
//					document.cookie = "userPwd="+u_pwd[1]+";expires="+days+";";
					setCookie("userId",u_id[1],10);
					setCookie("userPwd",u_pwd[1],10);
					
				}
				
				//成功后跳转登录
				window.location.href="/pages/index/login.html";
				
			}else{
				alert("填写信息");
			}
		})
		
		/*add_right.addEventListener("click",function(){
			
		})*/
		
	})
	
	//模块拖拽
	require(["jquery","drag","animate"],function($,drag,animate){
		//console.log($(".go-slide")[0]);
		drag($(".go-slide")[0],{x:true,y:false});
		
		$(".go-slide")[0].addEventListener("mouseup",function(){
			console.log($(".go-slide")[0].offsetLeft)
			let _offsetLeft = $(".go-slide")[0].offsetLeft;
			
			if(_offsetLeft>=205&&_offsetLeft<=225){
				//alert("pass")
				animate($(".go-slide")[0],{left:307})
				animate($(".slide-bgcolor")[0],{width:307})
				$(".go-slide").css("background","#fff url('https://m2.lefile.cn/myStatic/img/icon/slider_success.png') no-repeat center")
				$(".slide-bgcolor").text("验证成功！");
				$(".ban-select").show();
			}else{
				animate($(".go-slide")[0],{left:0});
				animate($(".slide-bgcolor")[0],{width:0})
				
			}
		})
		$(".go-slide")[0].addEventListener("mousemove",function(){
			$(".slide-bgcolor").width($(".go-slide")[0].offsetLeft);
		})
		
	})
	
})
